import 'package:flutter/material.dart';

class ListViewCase extends StatelessWidget {
  const ListViewCase({Key? key}) : super(key: key);

  // 获取整个的列表
  List<Widget> getList() {
    // List<Widget> list = [];
    // for (var i = 0; i < 10; i++) {
    //   list.add(Container(
    //     width: double.infinity,
    //     margin: EdgeInsets.all(10),
    //     decoration: BoxDecoration(
    //         color: Colors.blue, borderRadius: BorderRadius.circular(10)),
    //     height: 100,
    //     alignment: Alignment.center,
    //     child: Text(
    //       "第${i + 1}个",
    //       style: TextStyle(color: Colors.white, fontSize: 30),
    //     ),
    //   ));
    // }

    // React的实现写法
    return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((int value) {
      return Container(
        width: double.infinity,
        margin: EdgeInsets.all(10),
        decoration: BoxDecoration(
            color: Colors.blue, borderRadius: BorderRadius.circular(10)),
        height: 100,
        alignment: Alignment.center,
        child: Text(
          "第${value + 1}个",
          style: TextStyle(color: Colors.white, fontSize: 30),
        ),
      );
    }).toList();
    // return list;
  }

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: getList(),
    );
  }
}
